﻿using AutoMapper;
using B.S.BaseData.Domain.Base;
using B.S.BaseData.Domain.Interfaces;
using B.S.BaseData.Domain.RBAC;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.ReadAPI.Applications.Commands.Departments;
using B.S.BaseData.ReadAPI.DTOs.ResponseDto;
using CSRedis;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BaseData.ReadAPI.Controllers.Departments
{
	/// <summary>
	///  部门控制器
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
	public class DepartmentController : ControllerBase
	{
		IMediator  _mediator;
		CSRedisClient CSRedisClient;

		public DepartmentController(IMediator mediator, CSRedisClient cSRedisClient)
		{
			_mediator = mediator;
			CSRedisClient = cSRedisClient;
		}


		/// <summary>
		/// 获取部门树形信息
		/// </summary>
		/// <returns></returns>
		[HttpGet]
		public dynamic GetDepartmentMenuList()
		{
			try
			{
				if (CSRedisClient.Get("DepartMentMenuItem") != null) return CSRedisClient.Get("DepartMentMenuItem");

				var result= _mediator.Send(new GetDepartmentMenuItemCommand());
				CSRedisClient.Set("DepartMentMenuItem", result);
				return result;
			}
			catch (Exception)
			{

				throw;
			}
		}

		/// <summary>
		/// 获取部门列表
		/// </summary>
		/// <returns></returns>
		[HttpGet]
		public async Task<ApiResult<APIPaging<DepartmentDTO>>> GetDepartmentList([FromQuery] GetdepartmentListCommand cmd)
		{
			try
			{
				var	 result=await _mediator.Send(cmd);
				return result;
			}
			catch (Exception)
			{

				throw;
			}
		}



	}
}
